import Vue from 'vue';
import VueRouter from 'vue-router';
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import Usr from "@/views/Usr";
import Login from "@/views/Login";
import Main from "@/views/Main";
import BugInfo from "@/views/BugInfo";
import DistributionBug from "@/views/DistributionBug";
import QueryBugByState from "@/views/QueryBugByState";
// import FeedbackBug from "@/views/FeedbackBug";
import BugPriority from "@/views/BugPriority";
import Bugclassified from "@/views/Bugclassified"
import Bugstate from "@/views/Bugstate"
import WorkingHoursDay from "@/views/WorkingHoursDay"
import WorkingHoursMounth from "@/views/WorkingHoursMounth"
import BugList from "@/views/BugList"
import Buglevel from "@/views/Buglevel"
import Bugclassify from "@/views/Bugclassify" 
import Bugstatement from "@/views/Bugstatement"
import BugSeverityChart from "@/views/BugSeverityChart";
import BugClassifyChart from "@/views/BugClassifyChart";
import BugStateChart from "@/views/BugStateChart";
import ProjectManager from "@/views/ProjectManager"
import Feedback from "@/views/Feedback";
import BugFeedback from "@/views/BugFeedback";
import RoleAuthorityManagement from "@/views/RoleAuthorityManagement";

Vue.use(ElementUI);
Vue.use(VueRouter);

const VueRouterPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(to) {
    return VueRouterPush.call(this, to).catch(err => err)
}

const routes = [
    {
        path:'/',
        component:Login
    },
    {
        path: '/main',
        name: 'Main',
        component: Main,
        children: [
			{
			    path: '/ProjectManager',
			    name: 'ProjectManager',
			    component: ProjectManager
			},
            {
                path: '/usr',
                name: 'Usr',
                component: Usr
            },
            {
                path: '/bugInfo',
                name: 'BugInfo',
                component: BugInfo
            },
            {
                path: '/bugClassifyChart',
                name: 'BugClassifyChart',
                component: BugClassifyChart
            },
            {
                path: '/bugStateChart',
                name: 'BugStateChart',
                component: BugStateChart
            },
            {
                path: '/bugSeverityChart',
                name: 'BugSeverityChart',
                component: BugSeverityChart
            },
			{
				path: '/bugList',
				name: 'BugList',
				component: BugList
			},
			{
				path: '/Bugclassify',
				name: 'Bugclassify',
				component: Bugclassify
			},
			{
			    path: '/BugPriority',
			    name: 'BugPriority',
			    component: BugPriority
			},
			{
				path: '/Buglevel',
				name: 'Buglevel',
				component: Buglevel
			},
			{
				path: '/Bugstatement',
				name: 'Bugstatement',
				component: Bugstatement
			},
			{
				path: '/Bugclassified',
				name: 'Bugclassified',
				component: Bugclassified
			},
			{
				path: '/Bugstate',
				name: 'Bugstate',
				component: Bugstate
			},
			{
				path: '/WorkingHoursDay',
				name: 'WorkingHoursDay',
				component: WorkingHoursDay
			},
			{
				path: '/WorkingHoursMounth',
				name: 'WorkingHoursMounth',
				component: WorkingHoursMounth
			},
			{
			    path: '/Feedback',
			    name: 'Feedback',
			    component: Feedback,
				children: [
					{
					    path: '/BugFeedback',
					    name: 'BugFeedback',
					    component: BugFeedback,
					}
				]
			},
			{
			    path: '/QueryBugByState',
			    name: 'QueryBugByState',
			    component: QueryBugByState,
				children: [
					{
					    path: '/DistributionBug',
					    name: 'DistributionBug',
					    component: DistributionBug,
					}
				]
			},
			{
			    path: '/authority',
			    name: 'Authority',
			    component: RoleAuthorityManagement
			}
        ]
    }
]

const router = new VueRouter({
    mode: 'history',
    base: process.env.BASE_URL,
    routes
})

router.beforeEach((to,from,next)=>{
  //如果目的地是登陆组件 就直接放行
  if(to.path=="/"){
    next();
  }else{
    //如果不是登陆组件，先判断是否登录
    if(localStorage.getItem("token")){
      //已经登陆了直接放
      next();
    }else{
      //如果没登陆就放行到/login
      next("/");
    }
  }
})

export default router
